import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/data/store/config_store.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';

class HonourCardIndexPage extends StatefulWidget {
  const HonourCardIndexPage({Key? key}) : super(key: key);

  @override
  State<HonourCardIndexPage> createState() => _HonourCardIndexPageState();
}

class _HonourCardIndexPageState extends State<HonourCardIndexPage> {
  final controller = Get.find<HonourCardIndexController>();
  final state = Get.find<HonourCardIndexController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(
          title: Text('我的戎耀门牌'),
        ),
        body: SingleChildScrollView(
          child: _buildBody(),
        ),
      ),
    );
  }

  Widget _buildBody() {
    return Padding(
        padding: EdgeInsets.symmetric(horizontal: AppTheme.iDefaultPadding),
        child: Column(
          children: [
            Obx(() => state.honourCard.member == null
                ? SizedBox()
                : _buildCard(
                    '戎耀驿站标牌',
                    '申请实体标牌',
                    ConfigStore.to.baseFileUrl +
                        state.honourCard.member!.urlPath!,
                    null,
                    () {
                      Get.toNamed(RouterName.userMerchantEnterHonourCardApply,arguments: {
                        "id":Get.arguments['id'],
                        'image': state.honourCard.member!.urlPath!,
                        "isOk": state.honourCard.member!.status
                      });
                    })),
            Gaps.vGap12,
            Obx(() => state.honourCard.tyjr == null
                ? SizedBox()
                : _buildCard(
                    '戎创实体标牌',
                    '申请认证',
                    state.honourCard.tyjr!.urlPath == null
                        ? null
                        : ConfigStore.to.baseFileUrl +
                            state.honourCard.tyjr!.urlPath!,
                    Text('说明：商家法人为退役军人的可凭营业执照证件照片 和法人优待证申请该荣誉戎耀标牌。'),
                    () {
                      Get.toNamed(RouterName.userMerchantEnterHonourCardRcApply,arguments: {
                        "id":Get.arguments['id'],
                      });
                    })),
            Gaps.vGap12,
            Obx(() => state.honourCard.vip == null
                ? SizedBox()
                : _buildCard(
                    '会员单位标牌',
                    '申请认证',
                    state.honourCard.vip!.urlPath == null
                        ? null
                        : ConfigStore.to.baseFileUrl +
                            state.honourCard.vip!.urlPath!,
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                            '说明：商家为山西省爱国拥军促进会的会员单位，该戎耀标牌由山西省爱国拥军促进会发放。可联系山西省爱国拥军促进会申请成为会员单位。'),
                        Text('联系电话：15035465771')
                      ],
                    ),
                    null))
          ],
        ));
  }

  Widget _buildCard(title, buttonText, image, text, btnClick) {
    return Container(
      padding: EdgeInsets.all(AppTheme.iDefaultPadding),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(AppTheme.iDefaultPadding),
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '${title}',
                style: TextStyle(color: Colors.redAccent,fontSize: 18,fontWeight: FontWeight.bold)
              ),
              btnClick == null ? SizedBox(): TDButton(
                text: '${buttonText}',
                theme: TDButtonTheme.primary,
                size: TDButtonSize.small,
                onTap: () {
                  if (btnClick != null) {
                    btnClick();
                  }
                },
              )
            ],
          ),
          image == null ? SizedBox() : Gaps.vGap12,
          image == null
              ? SizedBox()
              : ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(10)),
                  child: MkLoadImage("${image}")),
          Gaps.vGap12,
          text == null ? SizedBox() : text
        ],
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<HonourCardIndexController>();
    super.dispose();
  }
}
